]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
messageTray: Allow to make notification buttons insensitive
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 17 May 2012 19:05:36 +0000 (21:05 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Fri, 18 May 2012 15:39:50 +0000 (17:39 +0200)
The availability of a notification action may depend on conditions,
so add a method to control the sensitivity of buttons which have
been added with addButton().

https://bugzilla.gnome.org/show_bug.cgi?id=651251

data/theme/gnome-shell.css
js/ui/messageTray.js

index 259be2695271684bd3d8754776bca617323463ab..a229653bda6c0433f342bd4b7501f09ea91a720d 100644 (file)
@@ -328,6 +328,11 @@ StScrollBar StButton#vhandle:hover
     background-gradient-end: rgba(255, 255, 255, 0.2);
 }
 
+.notification-icon-button:insensitive,
+.notification-button:insensitive {
+    color: #9f9f9f;
+}
+
 /* Panel */
 
 #panel {
index c7e34108658dbfa6dbc9812f1fc4a5acb5c49a9c..a5bd472516fedd125e66c95e40e32a093fe8e7ad 100644 (file)
@@ -746,6 +746,7 @@ const Notification = new Lang.Class({
         }
 
         let button = new St.Button({ can_focus: true });
+        button._actionId = id;
 
         if (this._useActionIcons && Gtk.IconTheme.get_default().has_icon(id)) {
             button.add_style_class_name('notification-icon-button');
@@ -765,6 +766,31 @@ const Notification = new Lang.Class({
         this.updated();
     },
 
+    // setButtonSensitive:
+    // @id: the action ID
+    // @sensitive: whether the button should be sensitive
+    //
+    // If the notification contains a button with action ID @id,
+    // its sensitivity will be set to @sensitive. Insensitive
+    // buttons cannot be clicked.
+    setButtonSensitive: function(id, sensitive) {
+        if (!this._buttonBox)
+            return;
+
+        let button = this._buttonBox.get_children().filter(function(b) {
+            return b._actionId == id;
+        })[0];
+
+        if (!button || button.reactive == sensitive)
+            return;
+
+        button.reactive = sensitive;
+        if (sensitive)
+            button.remove_style_pseudo_class('insensitive');
+        else
+            button.add_style_pseudo_class('insensitive');
+    },
+
     setUrgency: function(urgency) {
         this.urgency = urgency;
     },